package tracker.model.tests;

import junit.framework._
import junit.framework.Assert._
import bamboo.util.History

class HistoryTestCase extends TestCase {
  val defaultLine = ""
  val maxSize = 3
  val history: History[String] = new History[String](defaultLine, maxSize)
    
  def testEmpty {
    back(defaultLine)
    fwd(defaultLine)
  }

  def testSingleElement {
    val value = "A"
    add(value)
    fwd(value)
    back(value)
    fwd(defaultLine)
    fwd(defaultLine)
    back(value)
  }
    
  def testTwoElements {
    val valueA = "A"
    val valueB = "B"
    add(valueA)
    fwd(valueA)
    add(valueB)
    back(valueB)
    back(valueA)
    fwd(valueB)
    back(valueA)
    fwd(valueB)
    fwd(defaultLine)
    back(valueB)
  }

  def testSkipRepeatedElement {
    val valueA = "A"
    val valueB = "B"
    add(valueA)
    back(valueA)
    add(valueB)
    fwd(valueB)
    add(valueB)
    fwd(valueB)
    back(valueA)
    fwd(valueB)
    back(valueA)
    fwd(valueB)
    fwd(defaultLine)
    back(valueB)
  }

  def testSkipDefaultLine {
    val value = "A"
    add(value)
    add(defaultLine)
    back(value)
  }

  def testSkipDefaultLineAndRestart {
    val value = "A"
    add(value)
    back(value)
    fwd(defaultLine)
    add(defaultLine)
    back(value)
  }
  
  def testExceedSize {
    val valueA = "A"
    val valueB = "B"
    val valueC = "C"
    val valueD = "D"
    add(valueA)
    add(valueB)
    add(valueC)
    add(valueD)
    back(valueD)
    back(valueC)
    back(valueB)
    back(valueB)
    fwd(valueC)
    fwd(valueD)
    fwd(defaultLine)
  }

  def testExceedSizeTwice {
    val valueA = "A"
    val valueB = "B"
    val valueC = "C"
    val valueD = "D"
    val valueE = "E"
    add(valueA)
    add(valueB)
    add(valueC)
    add(valueD)
    back(valueD)
    back(valueC)
    add(valueE)
    back(valueE)
    back(valueD)
    back(valueC)
    back(valueC)
  }

  def testSkipNull {
    val valueA = "A"
    add(valueA)
    add(null)
    back(valueA)
  }
  
  def add = history.add _
  def back(expected: String) = assertEquals(expected, history.back)
  def fwd(expected: String) = assertEquals(expected, history.fwd)    
}
